﻿//-----------------------------------------------------------------------
// <copyright file="MaskedTextBoxFieldDefinition.cs" company="Jamie Knight">
// Copyright (c) Jamie Knight. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using DevKnightlie.WPF.AutoForm.FieldDefinitions;
using Xceed.Wpf.Toolkit;

namespace DevKnightlie.WPF.AutoForm.WPFToolkit.FieldDefinitions
{
    public class MaskedTextBoxFieldDefinition:BaseFieldDefinition
    {
        #region Properties

        /// <summary>
        /// Sets or returns the Mask property to apply to the control
        /// </summary>
        public String Mask
        {
            get; set; 
        }

        #endregion

        #region Methods

        public override void BuildInputControl()
        {
            MaskedTextBox textBox = new MaskedTextBox()
            {
                HorizontalContentAlignment = HorizontalAlignment.Left,
                VerticalContentAlignment = VerticalAlignment.Center,
                Mask = Mask
            };
            Binding textBinding = new Binding(PropertyName);
            BindingOperations.SetBinding(textBox, TextBox.TextProperty, textBinding);
            SetupEnabledBinding(textBox);
            InputControl = ContainerControl = textBox;
        }

        #endregion
    }
}
